package com.ddwanglife.juc;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> completedFuture = CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName()+"\t completableFuture");
//            int i= 10/0;
            return 1024;
        });
        System.out.println(
                completedFuture.whenComplete((t,u)->{
                    System.out.println("*******t: "+t);
                    System.out.println("*******u: "+u);
                }).exceptionally(f->{
                    System.out.println("*******exception: "+f.getMessage());
                    return 4444;
                }).get()
        );
    }
}
